// ml:run = $bin < input
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <utility>
#include <functional>

using ll = long long;
using pair = std::pair<ll, int>;

struct node { int to; ll cost; int co; };

ll const inf = (1ll) << 60;
int const maxn = 200000;
pair dist[maxn];
pair dist2[maxn];
std::vector<node> graph[maxn];

typedef std::vector<node>::iterator edge_iter;

int n, m, c, s, t;

void add_edge(int x, int y, ll z, int co)
{
	graph[x].push_back({y, z, co});
}

void dijkstra(int source)
{
	std::fill(dist, dist + n, std::make_pair(inf, -1));
	std::fill(dist2, dist2 + n, std::make_pair(inf, -1));
	dist[source] = {0, -1};
	typedef std::pair<ll, int> cost_end;
	std::priority_queue<cost_end, std::vector<cost_end>, std::greater<cost_end> > pq;

	pq.push(std::make_pair(0, source));
	while (!pq.empty()) {
		cost_end tmp = pq.top(); pq.pop();
		int u = tmp.second;
        if (dist[u].first < tmp.first) continue;

		for (edge_iter edge = graph[u].begin(); edge != graph[u].end(); ++edge) {
			int v = edge->to, co = edge->co;
            ll c = edge->cost;
            if (co != dist[u].second) {
                if (dist[u].first + c < dist[v].first) {
                    if (co != dist[v].second) {
                        dist2[v] = dist[v];
                        dist[v] = {dist[u].first + c, co};
                    } else {
                        dist[v] = {dist[u].first + c, co};
                    }
                    pq.push(std::make_pair(dist[v].first, v));
                } else if (co != dist[v].second && dist[u].first + c < dist2[v].first) {
                    dist2[v] = {dist[u].first + c, co};
                    pq.push(std::make_pair(dist[v].first, v));
                }
            }

            if (co != dist2[u].second) {
                if (dist2[u].first + c < dist[v].first) {
                    if (co != dist[v].second) {
                        dist2[v] = dist[v];
                        dist[v] = {dist2[u].first + c, co};
                    } else {
                        dist[v] = {dist2[u].first + c, co};
                    }
                    pq.push(std::make_pair(dist[v].first, v));
                } else if (co != dist[v].second && dist2[u].first + c < dist2[v].first) {
                    dist2[v] = {dist2[u].first + c, co};
                    pq.push(std::make_pair(dist[v].first, v));
                }
            }

            if (dist2[v].first < dist[v].first) std::swap(dist[v], dist2[v]);
		}
	}
}

int main()
{
	std::cin >> n >> m >> c;
	for (int i = 0, x, y, z, co; i < m; i++) {
		std::cin >> x >> y >> z >> co;
		x--; y--;
        add_edge(x, y, z, co);
	}
    int q; std::cin >> s >> q;
    s--; dijkstra(s);

    for (int i = 0; i < q; i++) {
        std::cin >> t; t--;
        if (dist[t].first >= inf)
            std::cout << "-1\n";
        else
            std::cout << std::min(dist[t].first, dist2[t].first) << "\n";
    }
}

